package com.itheima.health.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;
import com.itheima.health.utils.redis.RedisUtil;
import com.itheima.health.utils.resources.MessageConstant;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Reference(timeout = 1500,mock = "com.itheima.health.mock.OrderServiceMock")
    private OrderService orderService;

    @PostMapping("getCheckCode")
    public Result getCheckCode(@RequestBody String email){
        String email1 = JSONObject.parseObject(email).getString("email");
        orderService.getCode(email1);
        return new Result(true);
    }

    @PostMapping("add")
    public Result add(@RequestBody Map map){
        Order order = orderService.add(map);
        return new Result(true,MessageConstant.ADD_ORDER_SUCCESS,order);
    }

    @GetMapping("findOrderInfoByOrderId/{id}")
    public Result findOrderInfoByOrderId(@PathVariable("id")Integer id){
        Map map = orderService.findOrderInfoByOrderId(id);
        return new Result(map);
    }
}
